home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / PP_v1.4 / Source / misc.c < prev    next >
C/C++ Source or Header  |  1998-11-08  |  1KB  |  89 lines

  1. /* Misc.C - Miscellaneous functions for PP
  2. **
  3. ** calcsize() determines the size of a console window, given a text
  4. **          (possibly containing control sequences and newlines)
  5. **
  6. ** stoa()     short to ascii - converts a short to the equivalent string
  7. **
  8. ** stricmp()  Case independant string comparator (1 = strings matched)
  9. **
  10. ** This file belongs to the Powerpacker Patcher project
  11. **
  12. ** Copyright 1991, Michael Berg
  13. */
  14.  
  15. void calcsize
  16. (
  17.     register char *msg,
  18.  
  19.          short *left,  short *up,
  20.     register short *width, short *height
  21. )
  22. {
  23.     short maxwidth;
  24.  
  25.     *height = 8;
  26.     *width  = maxwidth = 0;
  27.  
  28.     while (*msg)
  29.     {
  30.         switch ((unsigned char)*msg++)
  31.         {
  32.             case 155: case 27:
  33.                 while (*msg && *msg++ != 'm')
  34.                     ;
  35.                 break;
  36.  
  37.             case '\n':
  38.                 *height += 8;
  39.                 if (*width > maxwidth) maxwidth = *width;
  40.                 *width = 0;
  41.                 break;
  42.  
  43.             default:
  44.                 *width += 8;
  45.         }
  46.     }
  47.  
  48.     if (*height > 8) *width = maxwidth;
  49.  
  50.     *height += 20;
  51.     *width  += 32;
  52.     *left    = 318-*width/2;
  53.     *up      = 100-*height/2;
  54. }
  55.  
  56. char *stoa(register short num, register char *ptr)
  57. {
  58.     short n;
  59.     char *np;
  60.  
  61.     if (!num)
  62.     {
  63.         *ptr++ = '0';
  64.         return(ptr);
  65.     }
  66.  
  67.     for (n = num; n; n /= 10)
  68.         ptr++;
  69.  
  70.     np = ptr;
  71.  
  72.     while (num)
  73.     {
  74.         *--ptr = (num % 10) + '0';
  75.         num /= 10;
  76.     }
  77.  
  78.     return(np);
  79. }
  80.  
  81. int stricmp(char *a,char *b)
  82. {
  83.     while (*a && *b)
  84.         if (toupper(*a++) != toupper(*b++))
  85.             return(0);
  86.  
  87.     return(1);
  88. }
  89.